package com.mlk.rbac.controller;

import com.mlk.core.component.page.Pager;
import com.mlk.core.util.ServerResponse;
import com.mlk.rbac.Service.SysAclModuleService;
import com.mlk.rbac.po.SysAclModule;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统模块controller
 * @author xulu
 */
@Controller
@RequestMapping("/rbac/acl")
public class SysAclModuleController {
	
	@Resource
	private SysAclModuleService sysAclModuleService;
	
	/**
	 * 权限维护页面
	 * @return
	 */
	@RequestMapping("index")
	public String index() {
		return "rbac/acl";
	}
	
	/**
	 * 权限列表
	 * @return
	 */
	@RequestMapping("list")
	@ResponseBody
	public Pager<SysAclModule> list(){
		List<SysAclModule> list = this.sysAclModuleService.list();
		Pager<SysAclModule> pager = new Pager<>();
		pager.setCount(Long.valueOf(list.size()));
		pager.setData(list);
		return pager; 
	}
	
	/**
	 * 获取菜单列表
	 */
	@GetMapping("/sysMenu")
	@ResponseBody
	public ServerResponse sysMenu() {
		return this.sysAclModuleService.sysMenu();
	}
	
	/**
	 * 删除权限
	 * @return
	 */
	@RequestMapping("/delAcl")
	@ResponseBody
	public ServerResponse delAcl(Integer id) {
		return  this.sysAclModuleService.delAcl(id);
	}
	
	/**
	 * 系统权限添加
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/aclAdd")
	public ServerResponse aclAdd(SysAclModule acl) {
		return this.sysAclModuleService.aclAdd(acl);
	}
	
	
	/**
	 * 系统权限更新
	 * @param acl
	 * @return
	 */
	@ResponseBody
	@RequestMapping("aclUpdate")
	public ServerResponse aclUpdate(SysAclModule acl) {
	return this.sysAclModuleService.aclUpdate(acl);	
	}

}
